<?php
namespace app\home\controller;
use think\Controller;
use think\Db;
use Alipay\lib\AlipayNotify;
use Des3\DES3;

class Picker extends Controller{
    public function index() {
        $region = db('region')->where('region_type', 'lt', 4)->select();
        foreach ($region as $item) {
            $tmpMap[$item['region_id']] = $item;
        }

        foreach ($region as $item) {
            if (isset($tmpMap[$item['parent_id']])) {
                $tmpMap[$item['parent_id']]['childrens'][] = &$tmpMap[$item['region_id']];
            } else {
                $tree[] = &$tmpMap[$item['region_id']];
            }
        }
//        $js = '+function($){ $.mob_data_picker1 = [';
//        foreach ($tree as $v) {
//            $js .= '{ "name":"'. $v['region_name'] .'", "code":"'. $v['region_id'] .'",';
//            if (isset($v['childrens']) && count($v['childrens']) > 0) {
//                $js .= '"sub": [';
//                foreach ($v['childrens'] as $c) {
//                    $js .= '{ "name":"'. $c['region_name'] .'", "code":"'. $c['region_id'] .'",';
//                    if (isset($c['childrens']) && count($c['childrens']) > 0) {
//                        $js .= '"sub": [';
//                        foreach ($c['childrens'] as $dc) {
//                            $js .= '{ "name":"'. $dc['region_name'] .'", "code":"'. $dc['region_id'] .'"},';
//                        }
//                        $js = trim($js, ',');
//                        $js .= ']},';
//                    } else {
//                        $js = trim($js, ',');
//                        $js .= '},';
//                    }
//                }
//                $js = trim($js, ',');
//                $js .= ']},';
//            } else {
//                $js = trim($js, ',');
//                $js .= '},';
//            }
//        }
//        $js .= '];}($);';
//
//        file_put_contents('./static/wechat/jquery_weui/js/data-picker1.js', $js);
        return xml($tree);

    }

    public function test() {
        return view();
    }

    public function taobao() {
        $url = 'https://lsp.wuliu.taobao.com/locationservice/addr/output_address_town_array.do?l3=110101&lang=zh-S';
        dump(get_data($url));
    }
}